package com.xique.door.project.elevator.controller;

import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.bean.request.elevator.ElevatorComElvInfoListWebRequest;
import com.xique.door.bean.request.elevator.ElevatorLastRunListWebRequest;
import com.xique.door.bean.request.elevator.ElevatorRunInfoWebRequest;
import com.xique.door.bean.request.elevator.ElevatorTotalMeterWebRequest;
import com.xique.door.biz.service.IElevatorBizService;
import com.xique.door.project.elevator.biz.service.IElevatorBizWebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author shd
 * @create 2021/10/15 8:51
 */
@RestController
@RequestMapping("/elv")
public class ElevatorWebController extends BaseController {

    @Autowired
    private IElevatorBizWebService elevatorBizWebService;

    @Autowired
    private IElevatorBizService elevatorBizService;

    /**
     * 回调
     * @author shd
     * @date 2021/10/25 16:18
     * @param faultJson
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @PostMapping("/notify")
    @ResponseBody
    public AjaxResult notify(String faultJson) {
        return elevatorBizService.syncFaultByImei(faultJson);
    };

    /**
     * 获取项目信息
     * @author shd
     * @date 2021/10/15 11:21
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getCommunityInfo")
    @ResponseBody
    public AjaxResult getCommunityInfo(Long parkId) {
        return elevatorBizWebService.getCommunityData(parkId);
    }

    /**
     * 获取电梯实时运行数据
     * @author shd
     * @date 2021/10/18 11:13
     * @param elvId
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getDeviceRunInfo")
    @ResponseBody
    public AjaxResult getDeviceRunInfo(Long elvId) {
        AjaxResult result = elevatorBizWebService.getDeviceRunInfo(elvId);
        if (AjaxResult.isError(result) && ("sys_code不能为空".equals(result.get(AjaxResult.MSG_TAG).toString()) || "token令牌错误".equals(result.get(AjaxResult.MSG_TAG).toString()))) {
            elevatorBizWebService.getSessionToken();
        } else {
            return result;
        }
        return elevatorBizWebService.getDeviceRunInfo(elvId);
    }

    /**
     * 获取电梯参数
     * @author shd
     * @date 2021/10/18 11:13
     * @param elvId
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getElevatorParameter")
    @ResponseBody
    public AjaxResult getElevatorParameter(Long elvId) {
        return elevatorBizWebService.getElevatorParameter(elvId);
    }

    /**
     * 电梯基础信息查询
     * @author shd
     * @date 2021/10/18 13:09
     * @param elvId
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getElvInfo")
    @ResponseBody
    public AjaxResult getElvInfo(Long elvId) {
        return elevatorBizWebService.getElvInfo(elvId);
    }

    /**
     * 获取电梯运行数据
     * @author shd
     * @date 2021/10/18 13:41
     * @param request
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getElvRun")
    @ResponseBody
    public AjaxResult getElvRun(ElevatorRunInfoWebRequest request) {
        return elevatorBizWebService.getElvRun(request);
    }

    /**
     * 获取频繁时段数据
     * @author shd
     * @date 2021/10/19 10:43
     * @param elvId
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getElvFrequentPeriod")
    @ResponseBody
    public AjaxResult getElvFrequentPeriod(Long elvId) {
        return elevatorBizWebService.getElvFrequentPeriod(elvId);
    }

    /**
     * 电梯总里程统计
     * @author shd
     * @date 2021/10/19 13:48
     * @param request
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getTotalMeter")
    @ResponseBody
    public AjaxResult getTotalMeter(ElevatorTotalMeterWebRequest request) {
        return elevatorBizWebService.getTotalMeter(request);
    }

    /**
     * 电梯等待时间统计,到达次数统计
     * @author shd
     * @date 2021/10/20 11:06
     * @param elvId
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getElvWaitTimeAndArrivalTimes")
    @ResponseBody
    public AjaxResult getElvWaitTimeAndArrivalTimes(Long elvId) {
        return elevatorBizWebService.getElvWaitTimeAndArrivalTimes(elvId);
    }

    /**
     * 获取事件列表
     * @author shd
     * @date 2021/10/20 13:45
     * @param request
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getElvEventList")
    @ResponseBody
    public AjaxResult getElvEventList(ElevatorLastRunListWebRequest request) {
        return elevatorBizWebService.getElvEventList(request);
    }

    /**
     * 获取最新事件
     * @author shd
     * @date 2021/10/20 13:45
     * @param request
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getElvLastEvent")
    @ResponseBody
    public AjaxResult getElvLastEvent(ElevatorLastRunListWebRequest request) {
        return elevatorBizWebService.getElvLastEvent(request);
    }

    /**
     * 服务开通信息统计
     * @author shd
     * @date 2021/10/21 9:49
     * @param parkId
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getServiceInfo")
    @ResponseBody
    public AjaxResult getServiceInfo(Long parkId) {
        return elevatorBizWebService.getServiceInfo(parkId);
    }

    /**
     * 地区服务开通信息统计
     * @author shd
     * @date 2021/10/21 9:49
     * @param code
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getAreaServiceInfo")
    @ResponseBody
    public AjaxResult getAreaServiceInfo(Long code) {
        return elevatorBizWebService.getAreaServiceInfo(code);
    }

    /**
     * 电梯安全性排行
     * @author shd
     * @date 2021/10/21 10:21
     * @param code
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getSecurityRanking")
    @ResponseBody
    public AjaxResult getSecurityRanking(Long code) {
        return elevatorBizWebService.getSecurityRanking(code);
    }

    /**
     * 社区电梯运行统计
     * @author shd
     * @date 2021/10/21 11:24
     * @param parkId
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getComElvRun")
    @ResponseBody
    public AjaxResult getComElvRun(Long parkId) {
        return elevatorBizWebService.getComElvRun(parkId);
    }

    /**
     * 社区电梯列表
     * @author shd
     * @date 2021/10/25 15:19
     * @param request
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getComElvInfo")
    @ResponseBody
    public AjaxResult getComElvInfo(ElevatorComElvInfoListWebRequest request) {
        return elevatorBizWebService.getComElvInfo(request);
    }

    /**
     * 基础信息(不使用)
     * @author shd
     * @date 2021/10/21 11:24
     * @param
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getBaseData")
    @ResponseBody
    @Deprecated
    public AjaxResult getBaseData() {
        return elevatorBizWebService.getBaseData();
    }

    /**
     * 获取地址信息
     * @author shd
     * @date 2021/10/22 15:00
     * @param code
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getRegionInfo")
    @ResponseBody
    public AjaxResult getRegionInfo(Long code) {
        return elevatorBizWebService.getRegionInfo(code);
    }

    /**
     * 根据地址获取电梯数量(不使用)
     * @author shd
     * @date 2021/10/22 15:00
     * @param code
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getRegionCount")
    @ResponseBody
    @Deprecated
    public AjaxResult getRegionCount(Long code) {
        return elevatorBizWebService.getRegionCount(code);
    }

    /**
     * 获取项目信息
     * @author shd
     * @date 2021/10/22 15:00
     * @param code
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getCommunity")
    @ResponseBody
    public AjaxResult getCommunity(Long code) {
        return elevatorBizWebService.getCommunity(code);
    }

    /**
     * 搜索项目
     * @author shd
     * @date 2021/10/29 10:11
     * @param content
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/searchCommunity")
    @ResponseBody
    public AjaxResult searchCommunity(String content) {
        return elevatorBizWebService.searchCommunity(content);
    }

    /**
     * 近30天故障
     * @author shd
     * @date 2021/10/25 11:09
     * @param code
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getFaultList")
    @ResponseBody
    public AjaxResult getFaultList(Long code) {
        return elevatorBizWebService.getFaultList(code);
    }

    /**
     * 根据小区统计近30天故障
     * @author shd
     * @date 2021/10/25 11:09
     * @param parkId
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getComFaultList")
    @ResponseBody
    public AjaxResult getComFaultList(Long parkId) {
        return elevatorBizWebService.getComFaultList(parkId);
    }

    /**
     * 总体概况
     * @author shd
     * @date 2021/10/25 11:46
     * @param code
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getGeneralData")
    @ResponseBody
    public AjaxResult getGeneralData(Long code) {
        return elevatorBizWebService.getGeneralData(code);
    }

    /**
     * 根据地区统计运行数据
     * @author shd
     * @date 2021/10/25 14:20
     * @param code
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getCityElvRun")
    @ResponseBody
    public AjaxResult getCityElvRun(Long code) {
        return elevatorBizWebService.getCityElvRun(code);
    }

    /**
     * 根据地区统计故障信息
     * @author shd
     * @date 2021/10/27 8:34
     * @param code
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getAreaFault")
    @ResponseBody
    public AjaxResult getAreaFault(Long code) {
        return elevatorBizWebService.getAreaFault(code);
    }

    /**
     * 获取电动车报警提醒
     * @author shd
     * @date 2021/10/28 11:54
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @GetMapping("/getElectromobileInfo")
    @ResponseBody
    public AjaxResult getElectromobileInfo() {
        return elevatorBizWebService.getElectromobileInfo();
    }
}
